﻿using System;
using System.ComponentModel;
using Loki;

namespace Luna.UI.Accounting
{
    public abstract class AccountingGraph : LunaViewModel
    {
        public abstract object DataSource { get; }

        #region  StartDate
        private static PropertyChangedEventArgs _StartDateChangeArgs = ObservableHelper.CreateArgs<AccountingGraph>(x => x.StartDate);

        private DateTime _StartDate;

        public DateTime StartDate
        {
            get
            {
                return _StartDate;
            }

            set
            {
                if (value != _StartDate)
                {
                    _StartDate = value;
                    NotifyChanged(_StartDateChangeArgs);
                }
            }
        }
        #endregion

        #region  EndDate
        private static PropertyChangedEventArgs _EndDateChangeArgs = ObservableHelper.CreateArgs<AccountingGraph>(x => x.EndDate);

        private DateTime _EndDate;

        public DateTime EndDate
        {
            get
            {
                return _EndDate;
            }

            set
            {
                if (value != _EndDate)
                {
                    _EndDate = value;
                    NotifyChanged(_EndDateChangeArgs);
                }
            }
        }
        #endregion

        #region  AccountID
        private static PropertyChangedEventArgs _AccountIDChangeArgs = ObservableHelper.CreateArgs<AccountingGraph>(x => x.AccountID);

        private Guid? _AccountID;

        public Guid? AccountID
        {
            get
            {
                return _AccountID;
            }

            set
            {
                if (value != _AccountID)
                {
                    _AccountID = value;
                    NotifyChanged(_AccountIDChangeArgs);
                }
            }
        }
        #endregion

        public AccountingGraph()
        {
            Init += AccountingLevelGraphViewModel_Init;
        }

        private void AccountingLevelGraphViewModel_Init(object P_Sender, EventArgs e)
        {
            this.WatchChange(this, x => x.StartDate, v => v.ReloadGraph);
            this.WatchChange(this, x => x.AccountID, v => v.ReloadGraph);
            this.WatchChange(this, x => x.EndDate, v => v.ReloadGraph);
        }

        protected abstract void ReloadGraph(object P_Sender, EventArgs e);
    }
}
